home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / ms_dos / rendir / src / rendir.c
Encoding:
C/C++ Source or Header  |  1993-07-08  |  1.2 KB  |  60 lines

  1. /*****************************************************************************
  2. *
  3. *    rendir.c
  4. *
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <jstring.h>
  11. #include <dos.h>
  12.  
  13. void rendir(int count,char **value)
  14. {
  15.     struct find_t filedata;
  16.     char buf1[80],buf2[80];
  17.     int ret;
  18.  
  19.     if (count != 2) {
  20.         printf("USAGE: rendir oldpath newpath(newname)\n");
  21.         exit (0);
  22.     }
  23.     strncpy(buf1, value[0], 80);
  24.     strncpy(buf2, value[1], 80);
  25.     if (_dos_findfirst(buf1, _A_SUBDIR|_A_NORMAL|_A_RDONLY|_A_ARCH,
  26.             &filedata) != 0) {
  27.         printf("pathが存在しません。\n");
  28.         exit (0);
  29.     }
  30.     if ((jstrchr(buf2, '\\') == NULL) && (jstrchr(buf1, '\\') != NULL)) {
  31.         strncpy(buf2, buf1, 80);
  32.         strcpy(jstrchr(buf2, '\\')+1, value[1]);
  33.     }
  34.     else if ((jstrchr(buf2, ':') == NULL) && (jstrchr(buf1, ':') != NULL)) {
  35.         strncpy(buf2, buf1,2);
  36.         strcpy(buf2+3, value[1]);
  37.     }
  38.     printf("'%s' to '%s'", buf1, buf2);
  39.  
  40.     ret = rename(buf1, buf2);    /*    ココが本体    */
  41.  
  42.     if (ret == 0) {
  43.         printf(" done.\n");
  44.     }
  45.     else {
  46.         printf(" failed.\n");
  47.     }
  48. }
  49.  
  50. void init(char *name)
  51. {
  52.     fprintf(stderr, "%s copyright (c) 1992 T.Nakatani\n", name);
  53. }
  54.  
  55. void main(int argc,char **argv)
  56. {
  57.     init(argv[0]);
  58.     rendir(argc-1, &argv[1]);
  59. }
  60.